-- Author  : Kurapica
-- Create Date : 2010/08/20

do
	IGAS:NewAddon("IGAS_Studio.Mdl_EventLoaderSelector")
	
	EventLoaderSelector = CreateFrame("Form", "EventLoaderSelector", coreF)
	EventLoaderSelector.Style = "LIGHT"
	EventLoaderSelector.Caption = L["Event Selector"]
	EventLoaderSelector.Resizable = false
	EventLoaderSelector.Height = 483.0
	EventLoaderSelector.Width = 659.0
	EventLoaderSelector.Visible = false
	EventLoaderSelector.FrameStrata = "FULLSCREEN_DIALOG"
	_Addon:AddFrame(EventLoaderSelector)

	CheckBox4 = CreateFrame("CheckBox", "CheckBox4", EventLoaderSelector)
	CheckBox4:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 24.0, -215.0)
	CheckBox4.Text = L["PLAYER_ENTERING_WORLD"]
	CheckBox4.Width = 210.0

	CheckBox6 = CreateFrame("CheckBox", "CheckBox6", EventLoaderSelector)
	CheckBox6:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 24.0, -357.0)
	CheckBox6.Text = L["VARIABLES_LOADED"]
	CheckBox6.Height = 25.0
	CheckBox6.Width = 166.0

	FontString3 = CreateFrame("FontString", "FontString3", EventLoaderSelector)
	FontString3:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 48.0, -152.0)
	FontString3.Text = L["This event fires immediately before PLAYER_ENTERING_WORLD.\nMost information about the game world should now be available to the UI.\nAll Sizing and Positioning of frames is supposed to be completed before this event fires.\nAddOns that want to do one-time initialization procedures once the player has \"entered the world\" should use this event instead of PLAYER_ENTERING_WORLD."]
	FontString3.JustifyH = "LEFT"
	FontString3.TextColor = {
		["red"] = 1.0,
		["alpha"] = 1.0,
		["blue"] = 1.0,
		["green"] = 1.0,
	}
	FontString3.Height = 64.0
	FontString3.Width = 591.0

	CheckBox5 = CreateFrame("CheckBox", "CheckBox5", EventLoaderSelector)
	CheckBox5:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 24.0, -311.0)
	CheckBox5.Text = L["PLAYER_ALIVE"]
	CheckBox5.Width = 127.0

	btnCancel = CreateFrame("NormalButton", "btnCancel", EventLoaderSelector)
	btnCancel:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 378.0, -437.0)
	btnCancel.Style = "NORMAL"
	btnCancel.Text = L["Cancel"]
	btnCancel.Height = 32.0
	btnCancel.Width = 186.0

	FontString6 = CreateFrame("FontString", "FontString6", EventLoaderSelector)
	FontString6:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 48.0, -375.0)
	FontString6.Text = L["Fired in response to the CVars, Keybindings and other associated \"Blizzard\" variables being loaded. Since key bindings and macros in particular may be stored on the server they event may be delayed a bit beyond the original loading sequence."]
	FontString6.JustifyH = "LEFT"
	FontString6.TextColor = {
		["red"] = 1.0,
		["alpha"] = 1.0,
		["blue"] = 1.0,
		["green"] = 0.9,
	}
	FontString6.Height = 46.0
	FontString6.Width = 577.0

	CheckBox2 = CreateFrame("CheckBox", "CheckBox2", EventLoaderSelector)
	CheckBox2:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 24.0, -80.0)
	CheckBox2.Text = L["SPELLS_CHANGED"]
	CheckBox2.Height = 32.0
	CheckBox2.Width = 153.0

	CheckBox1 = CreateFrame("CheckBox", "CheckBox1", EventLoaderSelector)
	CheckBox1:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 24.0, -31.0)
	CheckBox1.Text = L["ADDON_LOADED"]
	CheckBox1.Height = 29.0
	CheckBox1.Width = 139.0

	FontString5 = CreateFrame("FontString", "FontString5", EventLoaderSelector)
	FontString5:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 48.0, -325.0)
	FontString5.Text = L["This event fires after PLAYER_ENTERING_WORLD\
	Quest and Talent information should now be available to the UI"]
	FontString5.JustifyH = "LEFT"
	FontString5.TextColor = {
		["red"] = 1.0,
		["alpha"] = 1.0,
		["blue"] = 1.0,
		["green"] = 1.0,
	}
	FontString5.Height = 30.0
	FontString5.Width = 584.0

	FontString2 = CreateFrame("FontString", "FontString2", EventLoaderSelector)
	FontString2:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 48.0, -103.0)
	FontString2.Text = L["This event fires shortly before the PLAYER_LOGIN event and signals that information on the user's spells has been loaded and is available to the UI."]
	FontString2.JustifyH = "LEFT"
	FontString2.TextColor = {
		["red"] = 1.0,
		["alpha"] = 1.0,
		["blue"] = 1.0,
		["green"] = 1.0,
	}
	FontString2.Height = 29.0
	FontString2.Width = 597.0

	btnLoad = CreateFrame("NormalButton", "btnLoad", EventLoaderSelector)
	btnLoad:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 80.0, -437.0)
	btnLoad.Style = "NORMAL"
	btnLoad.Text = L["Load"]
	btnLoad.Height = 31.0
	btnLoad.Width = 182.0

	FontString4 = CreateFrame("FontString", "FontString4", EventLoaderSelector)
	FontString4:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 48.0, -234.0)
	FontString4.Text = L["This event fires immediately after PLAYER_LOGIN\
	Most information about the game world should now be available to the UI. If this is an interface reload rather than a fresh log in, talent information should also be available.\nAll Sizing and Positioning of frames is supposed to be completed before this event fires.\nThis event also fires whenever the player enters/leaves an instance and generally whenever the player sees a loading screen"]
	FontString4.JustifyH = "LEFT"
	FontString4.TextColor = {
		["red"] = 1.0,
		["alpha"] = 1.0,
		["blue"] = 1.0,
		["green"] = 1.0,
	}
	FontString4.Height = 78.0
	FontString4.Width = 590.0

	FontString1 = CreateFrame("FontString", "FontString1", EventLoaderSelector)
	FontString1:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 48.0, -52.0)
	FontString1.Text = L["This event fires whenever an AddOn has finished loading and the SavedVariables for that AddOn have been loaded from their file."]
	FontString1.JustifyH = "LEFT"
	FontString1.TextColor = {
		["red"] = 1.0,
		["alpha"] = 1.0,
		["blue"] = 1.0,
		["green"] = 1.0,
	}
	FontString1.Height = 24.0
	FontString1.Width = 600.0

	CheckBox3 = CreateFrame("CheckBox", "CheckBox3", EventLoaderSelector)
	CheckBox3:SetPoint("TOPLEFT", EventLoaderSelector, "TOPLEFT", 24.0, -133.0)
	CheckBox3.Text = L["PLAYER_LOGIN"]
	CheckBox3.Height = 23.0
	CheckBox3.Width = 130.0

	-- Scripts
	local _CallBack
	
	function _Addon.GetLoadEventList(callback)
		_CallBack = callback
		
		for i =1, 6 do
			_M["CheckBox"..i].Checked = false
		end
		
		EventLoaderSelector.Visible = true		
	end
	
	function btnCancel:OnClick()
		EventLoaderSelector.Visible = false
		_CallBack(nil)
	end
	
	function btnLoad:OnClick()
		local lst = {}
		
		for i =1, 6 do
			if _M["CheckBox"..i].Checked then
				tinsert(lst, _M["CheckBox"..i].Text)
			end
			if _M["CheckBox"..i].Text == L["ADDON_LOADED"] then
				-- Fire OnLoad event
				tinsert(lst, "OnLoad")
			end
		end
		
		tinsert(lst, "OnEnable")
		
		EventLoaderSelector.Visible = false
		
		return _CallBack(lst)
	end
end